home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Science⁄Math / Scientist's Helper src / s.helper.4 / regmain.c next >
C/C++ Source or Header  |  1986-02-06  |  21KB  |  686 lines

  1. #include "all.h"
  2. #include "regtabint.h"
  3.  
  4. main()
  5. {
  6.     int    t, i, j, k, ii, jj, kk, tBoolean, itop, ileft;
  7.     Handle TEScrH;
  8.     int    lastEvCoChar, lastEvPrChar;
  9.     long    nBytes, offsetTE, lengthTE;
  10.     float x, y;
  11.     char    c;
  12.     GrafPtr    savePort;
  13.     void    ScrollUp(), ScrollDown();
  14.     void    TScrollUp(), TScrollDown();
  15.     Rect    tRect, tRect2;
  16.     char    s[cmdWordLen], *gaddr;
  17.     
  18.     infinity = 0.0;
  19.     minfinity = -1.0 / infinity;
  20.     infinity = 1.0/infinity;
  21.     nCoeffs = 0;
  22.     for( i=0; i<33; i++ ) coeffs[i]=0.0;
  23.     
  24.     lastEvCoChar = FALSE;
  25.     lastEvPrChar = FALSE;
  26.  
  27.     macVars.numVars = 0;
  28.  
  29.     InitGraf(&thePort);  /* sets global variables thePort to nil and screenBits to Mac screen */
  30.     InitFonts();
  31.     FlushEvents(everyEvent,0);
  32.     InitWindows();
  33.     
  34.     /* set up menus */
  35.     InitMenus();
  36.     myMenu[apMenu] = GetMenu(apMenuRes);
  37.     AddResMenu(myMenu[apMenu],'DRVR'); /* desk accesories */
  38.     myMenu[fiMenu] = GetMenu(fiMenuRes);
  39.     myMenu[edMenu] = GetMenu(edMenuRes);
  40.     myMenu[wiMenu] = GetMenu(wiMenuRes);
  41.     myMenu[abMenu] = GetMenu(abMenuRes);
  42.     for ( i = 0; i < lastMenu; i++ )
  43.         InsertMenu(myMenu[i],0);
  44.     DrawMenuBar();
  45.  
  46.     TEInit();
  47.     InitDialogs(0L);
  48.     InitAllPacks();
  49.     InitPack(stdFile);    
  50.     SetCursor(&arrow);
  51.     SetRect(&dragRect, 0, 40, 700, 344);
  52.     SetRect(&growRect, 50, 50, windowWidth, windowHeight);
  53.     SetRect(&abortRect, 180, 0, 220, 20 );
  54.     SetRect(&wayOffScreen,1000,1000,1100,1100);
  55.     doneFlag = FALSE;
  56.     pendingFlag = FALSE;
  57.     InitCursor();
  58.     
  59.     /* set up graphics window */
  60.     grPortPtr = &grPort;
  61.     OpenPort( grPortPtr );
  62.     SetPort( grPortPtr );
  63.     grMap.rowBytes = windowWidth / 8 + 1;
  64.     if( (grMap.rowBytes & 1) != 0 ) grMap.rowBytes++;  /* make sure its even */
  65.     SetRect( &(grMap.bounds), 0, 0, windowWidth, windowHeight );
  66.     nBytes = grMap.rowBytes * (grMap.bounds.bottom - grMap.bounds.top);
  67.     grMap.baseAddr = NewPtr(nBytes);
  68.     grPort.portBits = grMap;
  69.     grPort.portRect = grMap.bounds;
  70.     SetPort( grPortPtr );
  71.     gaddr = (char*) grMap.baseAddr;
  72.     for( i=0; i<nBytes; i++ ) {
  73.         *gaddr = '\0';
  74.         gaddr++;
  75.         } /*end for*/
  76.     EraseRect( &(grPort.portRect) );
  77.     FrameRect( &(grPort.portRect) );
  78.     
  79.     SetPort( thePort );
  80.             
  81.     /* define windows */
  82.  
  83.     theWindow[edWindow] = GetNewWindow( edWndRes, &wRecord[0], -1L );
  84.     theWindow[prWindow] = GetNewWindow( prWndRes, &wRecord[1], -1L );
  85.     theWindow[grWindow] = GetNewWindow( grWndRes, &wRecord[2], -1L );
  86.     theWindow[coWindow] = GetNewWindow( coWndRes, &wRecord[3], -1L );
  87.     for( i=0; i<lastWindow; i++ ) {
  88.         theWindow[i]->txFont = 2;
  89.              vScroll[i] = GetNewControl( 256, theWindow[i]);
  90.         hScroll[i] = GetNewControl( 257, theWindow[i]);
  91.         theOrigin[i].h = 0; 
  92.         theOrigin[i].v = 0;
  93.         topPixel[i] = 1;
  94.         leftPixel[i] = 1;
  95.         }  /* end for */
  96.     
  97.     /* command window */
  98.     SetPort(theWindow[coWindow]);
  99.     SetRect(&tRect, 4, 4, 720, 364);
  100.     tRect2 = theWindow[coWindow]->portRect;
  101.     IndentRect( &tRect2 );
  102.     coText = TENew( &tRect, &tRect2 );
  103.     (*coText)->crOnly = -1;
  104.     TEInsert("Scientist\'s Helper, Version 2.7, by William Menke\r",50L,coText);
  105.     TEInsert("Caveat Emptor\r",14L,coText);
  106.     TEInsert("\r",1L,coText);
  107.     
  108.     /* procedure window */
  109.     SetPort(theWindow[prWindow]);
  110.     SetRect(&tRect, 4, 4, 720, 364);
  111.     tRect2 = theWindow[prWindow]->portRect;
  112.     IndentRect( &tRect2 );
  113.     prText = TENew( &tRect, &tRect2 );
  114.     (*prText)->crOnly = -1;
  115.     TEInsert("label sample\r",13L,prText);
  116.     TEInsert("prompt \'hi there\'\r",18L,prText);
  117.     TEInsert("return\r",7L,prText);
  118.  
  119.     /*table edit window */
  120.     SetPort(theWindow[edWindow]);
  121.     edText = TENew( &wayOffScreen, &wayOffScreen );
  122.     (*edText)->crOnly = -1;
  123.     (*edText)->txSize = 10;
  124.     (*edText)->txFont = geneva;
  125.     TextFont(geneva);
  126.     TextSize(10);
  127.     for( i=0; i<4; i++ ) {
  128.         SetRect( &(tabEd.name[i]), ((i+1)*100)+1, 1, (i+2)*100, 15 );
  129.         }
  130.     for( i=0; i<19; i++ ) {
  131.         SetRect( &(tabEd.row[i]), 1, ((i+1)*15)+1, 100, (i+2)*15 );
  132.         }
  133.     for( i=0; i<19; i++ ) {
  134.     for( j=0; j<4; j++ ) {
  135.         SetRect( &(tabEd.entry[i][j]), ((j+1)*100)+1,  ((i+1)*15)+1,  (j+2)*100,  (i+2)*15  );
  136.         } }
  137.     tabEd.activeEntry = FALSE;
  138.     tabEd.activeName = FALSE;
  139.     
  140.     LoadSg1(); /*force load of all segments of program*/
  141.     LoadSg2();
  142.     LoadSg3();
  143.     
  144.     InitTable(); /*initialize table*/
  145.     WritePhrase("> ");
  146.     
  147.     /* initialize procedure info */
  148.     mem.active = FALSE;
  149.     mem.stackPtr = -1;
  150.     mem.numLabels = 0;
  151.     loops.numLoops = 0;
  152.     
  153.     graph.xMin = 0.0;
  154.     graph.xMax = 1.0;
  155.     graph.yMin = 0.0;
  156.     graph.yMax = 1.0;
  157.     Graph2Vars();
  158.  
  159.     currentWindow = -1;
  160.     scrapIndex = -1;
  161.     SelectWindow(theWindow[coWindow]);
  162.     ZeroScrap();
  163.     setjmp(envbuf);
  164.     
  165.  
  166.     do {
  167.     
  168.         SystemTask();
  169.         
  170.         if( scrapIndex != (InfoScrap())->scrapCount ) {
  171.             scrapIndex = (InfoScrap())->scrapCount;
  172.             lengthTE = GetScrap( TEScrapHndl(), 'TEXT', &offsetTE );
  173.             if (lengthTE>0) (*((short *) 0x0AB0)) = lengthTE;
  174.             }
  175.             
  176.         GetNextEvent(everyEvent,&myEvent);
  177.         
  178.         while ( (*coText)->teLength > maxCoChars ) { /*nips top off of command window if too big*/
  179.             TECalText(coText);
  180.             i = (*coText)->selStart;
  181.             j = (*coText)->selEnd;
  182.             ii = (*coText)->lineStarts[0];
  183.             jj = (*coText)->lineStarts[1];
  184.             t = currentWindow;
  185.             GetPort( &oldPort );
  186.             SetPort( theWindow[coWindow] );
  187.             currentWindow = coWindow;
  188.             whichWindow = theWindow[currentWindow];
  189.             TESetSelect( (long)ii, (long)jj, coText );
  190.             TEDelete( coText );
  191.             kk = jj - ii;
  192.             TESetSelect( (long)(i-kk), (long)(j-kk), coText );
  193.             IfOutScroll(coText);
  194.             SetPort( oldPort );
  195.             currentWindow=t;
  196.             whichWindow = theWindow[currentWindow];
  197.             }
  198.             
  199.         if (mem.active && (!pendingFlag) && (myEvent.what==nullEvent) ) {   /*get command line from procedure memory*/
  200.             mem.stack[ mem.stackPtr ] ++;
  201.                     if (mem.stack[mem.stackPtr] >= (*prText)->nLines ) {                   
  202.                 ErrMsg(    "attempt to read past end of procedure" );
  203.                 } /*end if error*/
  204.             HLock((*prText)->hText);
  205.             j=(*prText)->lineStarts[mem.stack[mem.stackPtr]];
  206.             k=(*prText)->teLength;
  207.             ExtractLine( *((*prText)->hText), j, k, s );
  208.             HUnlock((*prText)->hText);
  209.             CmdFromWnd(s,FALSE);
  210.             } /*end if procedure is running*/
  211.                 
  212.         TEIdle(coText);
  213.         TEIdle(prText);
  214.         TEIdle(edText);
  215.  
  216.         switch(myEvent.what) {
  217.             case activateEvt:
  218.                 lastEvCoChar=FALSE;
  219.                 lastEvPrChar=FALSE;
  220.                    /* activate events return a window pointer as their message */
  221.                    /* find the window that corresponds to this pointer (if any) */
  222.                 
  223.                 /*cant activate procedure or edit window if procedure is running*/
  224.                 whichWindow = (WindowPtr)myEvent.message;
  225.                 GetWndNumber(whichWindow);
  226.                 if( currentWindow < 0 )  /* window not found */
  227.                     break;
  228.                 SetPort(theWindow[currentWindow]);
  229.                 if (myEvent.modifiers&1) {
  230.                     ShowControl(vScroll[currentWindow]);
  231.                     ShowControl(hScroll[currentWindow]);
  232.                     DrawControls(theWindow[currentWindow]);
  233.                     DrawGrowIcon(theWindow[currentWindow]);
  234.                     if( currentWindow == coWindow ) {
  235.                         TEActivate( coText );
  236.                              }
  237.                     else if( currentWindow == prWindow ) {
  238.                         TEActivate( prText );
  239.                         }
  240.                     else if( (currentWindow==edWindow) &&
  241.                                 (tabEd.activeName||tabEd.activeEntry) ) {
  242.                         TEActivate( edText );
  243.                         }
  244.                 }
  245.                 else {
  246.                     if( currentWindow == coWindow ) {
  247.                         TEDeactivate( coText );
  248.                         }
  249.                     else if( currentWindow == prWindow ) {
  250.                         TEDeactivate( prText );
  251.                         }
  252.                     else if( currentWindow == edWindow ) {
  253.                         TEDeactivate( edText );
  254.                         ClipRect( &(whichWindow->portRect) );
  255.                         }
  256.                     HideControl(vScroll[currentWindow]);
  257.                     HideControl(hScroll[currentWindow]);
  258.                 }
  259.                 break;
  260.                 
  261.             case updateEvt :
  262.                 lastEvCoChar=FALSE;
  263.                 lastEvPrChar=FALSE;
  264.  
  265.                 GetPort(&savePort);
  266.                 whichWindow = (WindowPtr)myEvent.message;
  267.                 GetWndNumber(whichWindow);
  268.                 if( currentWindow < 0 )  /* window not found */
  269.                     break;
  270.                 SetPort(theWindow[currentWindow]);
  271.                 BeginUpdate(theWindow[currentWindow]);
  272.                 EraseRect(&theWindow[currentWindow]->portRect);
  273.                 DrawWindow();
  274.                 EndUpdate(theWindow[currentWindow]);
  275.                 SetPort(savePort);
  276.                 break;
  277.                 
  278.             case mouseDown : 
  279.                 lastEvCoChar=FALSE;
  280.                 lastEvPrChar=FALSE;
  281.  
  282.                 /* code returns what type of window */
  283.                 code = FindWindow(pass(myEvent.where), &whichWindow);
  284.                 GetWndNumber(whichWindow);
  285.                     
  286.                 /* determine if this window is up front */
  287.                 if ( whichWindow == FrontWindow() )
  288.                     frontFlag = TRUE;
  289.                 else
  290.                     frontFlag = FALSE;
  291.  
  292.                 switch(code) {
  293.                     case inMenuBar :
  294.                         DoCommand(MenuSelect(pass(myEvent.where)));
  295.                         break;    
  296.                     case inSysWindow :
  297.                         SystemClick(&myEvent,whichWindow);
  298.                         break;
  299.                     case inDrag :
  300.                         if( frontFlag ) {
  301.                             DragWindow(whichWindow,pass(myEvent.where),
  302.                                     &dragRect);
  303.                             }
  304.                         else {
  305.                             if( !( (mem.active||pendingFlag) &&
  306.                               ( (currentWindow==prWindow) ||
  307.                                 (currentWindow==edWindow) ) ) ) {
  308.                               SelectWindow(whichWindow);
  309.                               }
  310.                               }
  311.                         break;
  312.                     case inGrow :
  313.                         if (frontFlag) {
  314.                             GrowWnd(whichWindow);
  315.                             }
  316.                         else {
  317.                             if( !( (mem.active||pendingFlag) &&
  318.                               ( (currentWindow==prWindow) ||
  319.                                 (currentWindow==edWindow) ) ) ) {
  320.                               SelectWindow(whichWindow);
  321.                               }
  322.                             }
  323.                         break;
  324.                     case inContent :
  325.                         if (frontFlag && (currentWindow==coWindow)) {
  326.                             GlobalToLocal(&myEvent.where);
  327.                             MyControl = FindControl(pass(myEvent.where),
  328.                                             whichWindow,&whichControl);
  329.                             switch(MyControl) {
  330.                             case inUpButton :
  331.                               TrackControl(whichControl,pass(myEvent.where),
  332.                                        TScrollUp);
  333.                               break;
  334.                             case inDownButton :
  335.                               TrackControl(whichControl,pass(myEvent.where),
  336.                                        TScrollDown);
  337.                               break;
  338.                             case inPageUp :
  339.                               TPageScroll(MyControl,-6400);
  340.                               break;
  341.                             case inPageDown :
  342.                               TPageScroll(MyControl,6400);
  343.                               break;
  344.                             case inThumb :
  345.                               t = TrackControl(whichControl,pass(myEvent.where),
  346.                                        0L);
  347.                               ScrollBits();
  348.                               break;
  349.                             default:
  350.                                   if( (myEvent.modifiers&shiftKey) == 1 )
  351.                                      tBoolean = TRUE;
  352.                                   else
  353.                                        tBoolean = FALSE;
  354.                                   TEClick(pass(myEvent.where),tBoolean,coText);
  355.                                   } /*end switch MyControl*/
  356.                             } /*end if coWindow*/
  357.                         else if (frontFlag && (currentWindow==grWindow)) {
  358.                             GlobalToLocal(&myEvent.where);
  359.                             MyControl = FindControl(pass(myEvent.where),
  360.                                             whichWindow,&whichControl);
  361.                             switch(MyControl) {
  362.                             case inUpButton :
  363.                               TrackControl(whichControl,pass(myEvent.where),
  364.                                        ScrollUp);
  365.                               break;
  366.                             case inDownButton :
  367.                               TrackControl(whichControl,pass(myEvent.where),
  368.                                        ScrollDown);
  369.                               break;
  370.                             case inPageUp :
  371.                               PageScroll(MyControl,-6400);
  372.                               break;
  373.                             case inPageDown :
  374.                               PageScroll(MyControl,6400);
  375.                               break;
  376.                             case inThumb :
  377.                               t = TrackControl(whichControl,pass(myEvent.where),
  378.                                        0L);
  379.                               ScrollBits();
  380.                               break;
  381.                             default:
  382.                                i = (myEvent.where.h+theOrigin[grWindow].h);
  383.                                j = (myEvent.where.v+theOrigin[grWindow].v);
  384.                                InvGraphScale( i, j, &x, &y );
  385.                                RToS( x, s );
  386.                                currentWindow=coWindow;
  387.                                whichWindow=theWindow[coWindow];
  388.                                SetPort(theWindow[currentWindow]);
  389.                                if(!SetVar("xpos",s)){
  390.                                  ErrMsg("couldnt set xpos variable");
  391.                                  }
  392.                                WritePhrase(s);
  393.                                WritePhrase(" ");
  394.                                RToS( y, s );
  395.                                if(!SetVar("ypos",s)){
  396.                                  ErrMsg("couldnt set ypos variable");
  397.                                  }
  398.                                WriteLine(s);
  399.                                currentWindow=grWindow;
  400.                                whichWindow=theWindow[grWindow];
  401.                                SetPort(theWindow[currentWindow]);
  402.                                if(pendingFlag) {
  403.                                    currentWindow=grWindow;
  404.                                  whichWindow=theWindow[coWindow];
  405.                                  SelectWindow(theWindow[coWindow]);
  406.                                  PostEvent(keyDown,(long)'\r');
  407.                                  longjmp(envbuf,-1);
  408.                                  }
  409.                             } /*end switch MyControl */
  410.                             } /*end if grWindow*/
  411.                         else if (frontFlag && (currentWindow==prWindow)) {
  412.                             GlobalToLocal(&myEvent.where);
  413.                             MyControl = FindControl(pass(myEvent.where),
  414.                                             whichWindow,&whichControl);
  415.                             switch(MyControl) {
  416.                                 case inUpButton :
  417.                               TrackControl(whichControl,pass(myEvent.where),
  418.                                        TScrollUp);
  419.                               break;
  420.                             case inDownButton :
  421.                               TrackControl(whichControl,pass(myEvent.where),
  422.                                        TScrollDown);
  423.                               break;
  424.                             case inPageUp :
  425.                               TPageScroll(MyControl,-6400);
  426.                               break;
  427.                             case inPageDown :
  428.                               TPageScroll(MyControl,6400);
  429.                               break;
  430.                             case inThumb :
  431.                               t = TrackControl(whichControl,pass(myEvent.where),
  432.                                        0L);
  433.                               ScrollBits();
  434.                               break;
  435.                             default:
  436.                                   if( (myEvent.modifiers&shiftKey) == 1 )
  437.                                      tBoolean = TRUE;
  438.                                   else
  439.                                        tBoolean = FALSE;
  440.                                   TEClick(pass(myEvent.where),tBoolean,prText);
  441.                                   } /*end switch MyControl*/
  442.                             }/*end if prWindow*/
  443.                         else if (frontFlag && (currentWindow==edWindow)) {
  444.                             GlobalToLocal(&myEvent.where);
  445.                             MyControl = FindControl(pass(myEvent.where),
  446.                                             whichWindow,&whichControl);
  447.                             switch(MyControl) {
  448.                             case inUpButton :
  449.                               TrackControl(whichControl,pass(myEvent.where),
  450.                                        TScrollUp);
  451.                               break;
  452.                             case inDownButton :
  453.                               TrackControl(whichControl,pass(myEvent.where),
  454.                                        TScrollDown);
  455.                               break;
  456.                             case inPageUp :
  457.                               TPageScroll(MyControl,-6400);
  458.                               break;
  459.                             case inPageDown :
  460.                               TPageScroll(MyControl,6400);
  461.                               break;
  462.                             case inThumb :
  463.                               t = TrackControl(whichControl,pass(myEvent.where),
  464.                                        0L);
  465.                               ScrollBits();
  466.                               break;
  467.                             default:
  468.                                ileft = (GetCtlValue(hScroll[edWindow])/1024)+1;
  469.                                itop = (GetCtlValue(vScroll[edWindow])/8)+1;
  470.                                ResizePRect();
  471.                                    ClipRect( &pRect );
  472.                                if( tabEd.activeName || tabEd.activeEntry ) {
  473.                                     /*get text from edit record and delete the text*/
  474.                                    HLock((*edText)->hText);
  475.                                 i=(*edText)->teLength;
  476.                                 ExtractLine( *((*edText)->hText), 0, (i-1), s );
  477.                                 HUnlock((*edText)->hText);
  478.                                 TEDeactivate(edText);
  479.                                 TESetSelect( 0L, (long)i, edText );
  480.                                 TEDelete(edText);
  481.                                 }
  482.                               if( tabEd.activeName ) {
  483.                                     if( GoodCol(tabEd.c)==0 ) {
  484.                                   strcpy( table.header.colName[tabEd.c-1], s );
  485.                                   }
  486.                                 else {
  487.                                   SysBeep(5);
  488.                                   strcpy( s, " ");
  489.                                   }
  490.                                 EraseRect( &(tabEd.name[tabEd.c-ileft]) );
  491.                                 MoveTo( (tabEd.name[tabEd.c-ileft]).left+1,
  492.                                          (tabEd.name[tabEd.c-ileft]).bottom-2 );
  493.                                 DrawText( s, 0, strlen(s) );
  494.                                 }
  495.                               else if( tabEd.activeEntry ) {
  496.                                      if( (GoodCol(tabEd.c)==0) && (GoodRow(tabEd.r)==0) ) {
  497.                                         if( table.header.interpolated && (tabEd.c==1) ) {
  498.                                             SysBeep(5);
  499.                                         GetTable( tabEd.r, 1, &x );
  500.                                         RToS(x,s);
  501.                                                 }
  502.                                          else {
  503.                                                 SToR( s, &x, TRUE );
  504.                                         RToS( x, s, TRUE );
  505.                                             SetTable( tabEd.r, tabEd.c, x, FALSE );
  506.                                             }
  507.                                      }
  508.                                   else {
  509.                                      SysBeep(5);
  510.                                      strcpy(s,"");
  511.                                      }
  512.                                  EraseRect( &(tabEd.entry[tabEd.r-itop][tabEd.c-ileft]) );
  513.                                  MoveTo( (tabEd.entry[tabEd.r-itop][tabEd.c-ileft]).left+1,
  514.                                          (tabEd.entry[tabEd.r-itop][tabEd.c-ileft]).bottom-2 );
  515.                                  DrawText( s, 0, strlen(s) );
  516.                                 }
  517.                                   tabEd.activeName=FALSE;
  518.                               tabEd.activeEntry=FALSE;
  519.                               for( j=0; j<4; j++ ) {
  520.                                   if( PtInRect( pass(myEvent.where), &(tabEd.name[j]) ) ){
  521.                                     tabEd.c=ileft+j;
  522.                                     tabEd.activeName=TRUE;
  523.                                     jj=j;
  524.                                     break;
  525.                                     } /*end if*/
  526.                                 } /*end for*/
  527.                               for( i=0; (i<19)&&(!tabEd.activeName);i++ ) {
  528.                               for( j=0; j<4; j++ ) {
  529.                                   if( PtInRect( pass(myEvent.where), &(tabEd.entry[i][j]) ) ) {
  530.                                     tabEd.r=itop+i;
  531.                                     tabEd.c=ileft+j;
  532.                                     tabEd.activeEntry=TRUE;
  533.                                     ii=i;
  534.                                     jj=j;
  535.                                     break;
  536.                                     } /*end if*/
  537.                                 } } /*end fors*/
  538.                               if( tabEd.activeName ) {
  539.                                    if( GoodCol(tabEd.c)!=0 ) {
  540.                                          SysBeep(5);
  541.                                      tabEd.activeName=FALSE;
  542.                                      break;
  543.                                      }
  544.                                      (*edText)->destRect=tabEd.name[jj];
  545.                                  ResizeEdBox();
  546.                                  TESetSelect( 0L, (long)(*edText)->teLength, edText );
  547.                                  TEDelete(edText);
  548.                                  TEInsert( table.header.colName[tabEd.c-1], 
  549.                                         (long)strlen(table.header.colName[tabEd.c-1]), edText );
  550.                                  TESetSelect( 0L, (long)((*edText)->teLength), edText );
  551.                                  TEActivate( edText );
  552.                                  TEUpdate(&((*edText)->viewRect),edText);
  553.                                   }
  554.                               else if( tabEd.activeEntry ) {
  555.                                      if( (GoodRow(tabEd.r)!=0) || (GoodCol(tabEd.c)!=0)
  556.                                       || ((tabEd.c==1)&&table.header.interpolated) ) {
  557.                                       SysBeep(5);
  558.                                       tabEd.activeEntry=FALSE;
  559.                                       break;
  560.                                       }
  561.                                      (*edText)->destRect=tabEd.entry[ii][jj];
  562.                                  ResizeEdBox();
  563.                                  GetTable( tabEd.r, tabEd.c, &x );
  564.                                  RToS( x, s );
  565.                                  TESetSelect( 0L, (long)(*edText)->teLength, edText );
  566.                                  TEDelete(edText);
  567.                                  TEInsert( s, (long)strlen(s), edText );
  568.                                  TESetSelect( 0L, (long)((*edText)->teLength), edText );
  569.                                  TEActivate( edText );
  570.                                  TEUpdate(&((*edText)->viewRect),edText);
  571.                                   }
  572.                               else {
  573.                                   SysBeep(5);
  574.                                 }
  575.                               } /*end switch MyControl*/
  576.                             }/*end if edWindow*/
  577.                         else {
  578.                             if( !( (mem.active||pendingFlag) &&
  579.                               ( (currentWindow==prWindow) ||
  580.                                 (currentWindow==edWindow) ) ) ) {
  581.                               SelectWindow(whichWindow);
  582.                               }
  583.                               }
  584.                         break;
  585.                     } /* end switch code */
  586.                 break;
  587.                 
  588.             case keyDown:
  589.             case autoKey:
  590.                 if( mem.active && (!pendingFlag) ) {
  591.                     break;
  592.                     }
  593.                 c = (char) (myEvent.message & charCodeMask);
  594.                 whichWindow = FrontWindow();
  595.                 GetWndNumber(whichWindow);
  596.                 SetPort(whichWindow);
  597.                 if( ((myEvent.modifiers & cmdKey) != 0) 
  598.                   && ((currentWindow==coWindow) || (currentWindow==prWindow)
  599.                   || (currentWindow==grWindow)  || (currentWindow==edWindow) )
  600.                   ) {
  601.                        DoCommand( MenuKey(c) );
  602.                        } /*end if cmdkey down*/
  603.                 else if (currentWindow == coWindow) {
  604.                           if( c==(char)3 ) c='\r'; /*enter key is return*/
  605.                           TEKey( c, coText );
  606.                       if( (!lastEvCoChar) || (c=='\r') ) IfOutScroll( coText);
  607.                       if( (c=='\r') &&
  608.                           ((*coText)->selEnd >= ((*coText)->teLength-1)) ) {
  609.                               HLock((*coText)->hText);
  610.                         j=(*coText)->lineStarts[(*coText)->nLines-1];
  611.                         k=(*coText)->teLength-2;
  612.                         ExtractLine( *((*coText)->hText), j, k, s );
  613.                         HUnlock((*coText)->hText);
  614.                         CmdFromWnd(s,TRUE);
  615.                             } /*end if return*/
  616.                       lastEvCoChar=TRUE;
  617.                           lastEvPrChar=FALSE;
  618.                               } /* end if coWindow and frontwindow */
  619.                 else if( (currentWindow==prWindow) && (!pendingFlag) ){
  620.                           if( c==(char)3 ) c='\r'; /*enter key is return*/
  621.                           TEKey( c, prText );
  622.                       if( (!lastEvPrChar) || (c=='\r') ) IfOutScroll( prText );
  623.                           lastEvCoChar=FALSE;
  624.                           lastEvPrChar=TRUE;
  625.                           } /*end if prWindow and frontwindow*/
  626.                 else if( currentWindow==grWindow) {
  627.                     lastEvCoChar=FALSE;
  628.                     lastEvPrChar=FALSE;
  629.                     SysBeep(5);
  630.                     }
  631.                 else if( (currentWindow==edWindow) && (tabEd.activeEntry||tabEd.activeName) ){
  632.                     lastEvCoChar=FALSE;
  633.                     lastEvPrChar=FALSE;
  634.                       ResizePRect();
  635.                       ClipRect( &pRect );
  636.                           if( c==(char)3 ) c='\r'; /*enter key is return*/
  637.                           TEKey( c, edText );
  638.                       if( c=='\r' ) {
  639.                               HLock((*edText)->hText);
  640.                         ExtractLine( *((*edText)->hText), 0, (*edText)->teLength-1, s );
  641.                         HUnlock((*edText)->hText);
  642.                         if( tabEd.activeName ) {
  643.                             strcpy( table.header.colName[tabEd.c-1], s );
  644.                             tabEd.activeName=FALSE;
  645.                             strcpy(s,"");
  646.                             }
  647.                          else if( tabEd.activeEntry ) {
  648.                              SToR( s, &x );
  649.                              SetTable( tabEd.r, tabEd.c, x, FALSE );
  650.                              if (GoodRow(tabEd.r+1)==0) {
  651.                                 tabEd.r++;
  652.                                 GetTable(tabEd.r,tabEd.c,&x);
  653.                             RToS( x, s );
  654.                             }
  655.                                  else {
  656.                                 tabEd.activeEntry=FALSE;
  657.                                 strcpy(s,"");
  658.                             }
  659.                              SetCtlValue(vScroll[edWindow],GetCtlValue(vScroll[edWindow])+8);
  660.                              }
  661.                          ClipRect( &(whichWindow->portRect) );
  662.                          InvalRect(&(whichWindow->portRect));
  663.                          (*edText)->destRect = wayOffScreen;
  664.                          (*edText)->viewRect = wayOffScreen;
  665.                          TESetSelect( 0L, (long)(*edText)->teLength, edText );
  666.                          TEDelete(edText);
  667.                          TEInsert(s,(long)strlen(s),edText);
  668.                          TESetSelect( 0L, (long)(*edText)->teLength, edText );
  669.                          TEActivate(edText);
  670.                          } /*end if return*/
  671.                           } /* end if edWindow and frontwindow */
  672.                 break;
  673.     
  674.             } /* end switch what event */
  675.         } while ( !(doneFlag=done()) ) ;
  676.         
  677.     TEScrH=TEScrapHndl();
  678.     HLock(TEScrH);
  679.     ZeroScrap();
  680.     PutScrap( TEGetScrpLen(), 'TEXT', *TEScrH );
  681.     HUnlock(TEScrH);
  682.     scrapIndex = (InfoScrap())->scrapCount;
  683.  
  684.     ExitToShell();
  685. } /* end main */
  686.